layui.define(['layer'], function (exports) {
    var Message = function () {}

    Message.prototype.success = function (message, callback) {
        return layui.layer.msg(message || '操作成功', {
            icon: 1,
            time: 1500
        }, callback);
    }

    Message.prototype.failure = function (message, callback) {
        return layui.layer.msg(message || '未知错误', {
            icon: 2,
            time: 1500
        }, callback);
    }

    Message.prototype.loading = function (message, callback) {
        return layui.layer.msg(message || '正在加载', {
            icon: 16,
            time: 0
        }, callback);
    }

    Message.prototype.confirm = function (message, callback) {
        return layui.layer.confirm(message, function (index) {
            callback.call(this, index);

            layui.layer.close(index);
        });
    }

    Message.prototype.close = function (index) {
        return layui.layer.close(index);
    }

    // 判断父组件是否存在，如果存在就使用父组件
    if (typeof window.parentMessage === 'function') {
        exports('message', window.parentMessage);
    } else {
        exports('message', new Message());
    }
});